# Contributor: Danct12 <danct12@disroot.org>
# Contributor: Asriel Dreemurr <asriel.danctnix@gmail.com>
# Maintainer: Danct12 <danct12@disroot.org>
pkgname=bullet
pkgver=2.89
pkgrel=5
pkgdesc="A 3D Collision Detection and Rigid Body Dynamics Library for games and animation"
url="https://pybullet.org/Bullet/phpBB3/"
arch="all"
license="Zlib"
makedepends="cmake doxygen graphviz-dev ttf-dejavu mesa-dev glu-dev python3-dev py3-numpy-dev samurai"
options="!check" # cannot build tests
subpackages="$pkgname-dev $pkgname-doc"
source="bullet3-$pkgver.tar.gz::https://github.com/bulletphysics/bullet3/archive/$pkgver.tar.gz"
builddir="$srcdir/bullet3-$pkgver"

build() {
	cmake -B build -G Ninja \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DBUILD_SHARED_LIBS=True \
		-DBUILD_BULLET2_DEMOS=0 \
		-DBUILD_CPU_DEMOS=0 \
		-DINSTALL_LIBS=1 \
		-DINSTALL_EXTRA_LIBS=1 \
		-DBUILD_PYBULLET=ON \
		-DBUILD_PYBULLET_NUMPY=ON \
		-DBUILD_OPENGL3_DEMOS=0 \
		-DBUILD_UNIT_TESTS=0 \
		-DUSE_DOUBLE_PRECISION=ON \
		-DCMAKE_BUILD_TYPE=MinSizeRel
	cmake --build build

	# doxygen is too slow on riscv64 at the moment...
	if [ "$CARCH" != "riscv64" ]; then
		doxygen
	fi
}

package() {
	DESTDIR="$pkgdir" cmake --install build	# avoid libtool errors

	# Install LICENSE
	install -Dm644 "$builddir"/LICENSE.txt $pkgdir/usr/share/licenses/$pkgname/LICENSE
}

doc() {
	default_doc

	# install docs
	install -Dm644 "$builddir"/docs/GPU_rigidbody_using_OpenCL.pdf $subpkgdir/usr/share/doc/bullet/GPU_rigidbody_using_OpenCL.pdf
	install -Dm644 "$builddir"/docs/Bullet_User_Manual.pdf $subpkgdir/usr/share/doc/bullet/Bullet_User_Manual.pdf
	install -Dm644 "$builddir"/docs/BulletQuickstart.pdf $subpkgdir/usr/share/doc/bullet/BulletQuickstart.pdf

	if [ "$CARCH" != "riscv64" ]; then
		cp -r "$builddir"/html $subpkgdir/usr/share/doc/bullet/html
	fi
}

sha512sums="
3c4ba6a3b3623ef44dd4a23e0bc2e90dec1f2b7af463edcb886e110feac1dfb4a91945f0ed640052cac228318539e275976d37238102fb10a0f78aef065a730b  bullet3-2.89.tar.gz
"
